import React, { useEffect, useState } from 'react';
import {Button, Checkbox, Form, Input,Divider,Space, Table, Tag,Radio,notification } from 'antd';
import { useLocation,useNavigate } from 'react-router-dom';
import { shixiang_geng,shixiang_zeng } from '../../../api/shiku';
import './Addshi.scss'
interface Props{

}
const { TextArea } = Input;
function Addshi(props:Props) {
  var navigate = useNavigate();
    var [shijian,setShi]=useState(new Date())
    // 生命周期
    useEffect(()=>{
        if(location.state){
            const {title,state,type,mId,game,adminname,time}=location.state
        form.setFieldsValue({title,state,type,mId,game,adminname,time})
                
            }else{
              form.setFieldValue("adminname",'张三')
            }
    },[])
   // 新增
   var zeng=async (can:any)=>{
    var time=new Date()
    can.time=time
   
      var res=await shixiang_zeng(can)

      navigate('/index/management/Shixiangku')

     
   }




    /// 更新表单
    var geng=async (can:any)=>{
      var time=new Date()
      can.time=time
      var res=await shixiang_geng(can)
      console.log(res.data)
      notification.success({
        type:'success',
        message:'修改成功'
    })
      if(res.data.code==200){
        navigate('/index/management/Shixiangku')
       
      }
    }
    var location= useLocation()
    console.log(location.state)
   
    const [form] = Form.useForm();
    
    const onFinish = (values: any) => {
        console.log('Success:', values);
        if(values.mId){
          geng(values)
        }else{
          zeng(values)
        }
       
      };
      
      const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);
      };
    return (
        <div className='addshi'>
            <header className='header'>
                <h2>{location.state ? '编辑事项':'新增事项'}</h2>
                {/* <div>
                    <Button size='small'>保存草稿</Button>
                    <Button size='small' >提交</Button>
                    <Button size='small' >保存</Button>
                    <Button size='small' >发布新版本</Button>
                </div> */}
            </header>
            <Divider orientationMargin="0" orientation="left" ><b>主要信息</b></Divider>
            <Form
            form={form}
            className='shang'
           
    name="basic"
    labelCol={{ span: 4 }}
    wrapperCol={{ span: 20 }}
    // style={{ maxWidth: 600 }}
    initialValues={{ remember: true }}
    onFinish={onFinish}
    onFinishFailed={onFinishFailed}
    autoComplete="off"
  >
     <Form.Item className='dingwei'>
      
      <Button  htmlType="submit" >保存草稿</Button>
                    <Button   htmlType="submit" >提交</Button>
                    <Button   htmlType="submit">保存</Button>
                    <Button   htmlType="submit" >发布新版本</Button>
    </Form.Item>
    <Form.Item
    hidden
      label="事项"
      name="mId"
    >
  
    <Input />
  
    </Form.Item>
    <Form.Item
      label="事项名称"
      name="title"
      rules={[{ required: true, message: 'Please input your username!' }]}
    >
  
    <Input />
  
    </Form.Item>
    <Form.Item
      label="所属目录"
      name="type"
      rules={[{ required: true, message: 'Please input your username!' }]}
    >
     <Radio.Group>
        <Radio value="行政审批">行政审批</Radio>
        <Radio value="人事审批">人事审批</Radio>
        <Radio value="客服审批">客服审批</Radio>
        
       
      </Radio.Group>
    </Form.Item>
    <Form.Item
      label="办理结果"
      name="game"
      rules={[{ required: true, message: 'Please input your username!' }]}
    >
  
  <Radio.Group>
        <Radio value="失败">失败</Radio>
        <Radio value="成功">成功</Radio>
       
        
       
      </Radio.Group>
  
    </Form.Item>
    <Form.Item
      label="事项状态"
      name="state"
      rules={[{ required: true, message: 'Please input your username!' }]}
    
    >
    <Radio.Group>
        <Radio value="完成状态">完成</Radio>
        <Radio value="取消状态">取消</Radio>
        <Radio value="待确定状态">待确定</Radio>
       
       
      </Radio.Group>
    </Form.Item>
    <Form.Item
      label="办理人"
      name="adminname"
      rules={[{ required: true, message: 'Please input your username!' }]}
    
    >
     <Input disabled />
    </Form.Item>
    {/* <Form.Item
      label="办理时间"
      name="time"
      rules={[{ required: true, message: 'Please input your username!' }]}
    
    >
     <Input value={shijian} disabled />
    </Form.Item> */}
   

    {/* <Form.Item
      label="事项编码"
      name="sxcode"
      rules={[{ required: true, message: 'Please input your username!' }]}
    >
    <Input />
    </Form.Item> */}
    {/* <Form.Item
      label="事项排序号"
      name="bianma"
      rules={[{ required: true, message: 'Please input your username!' }]}
    >
    <Input />
    </Form.Item> */}
   
    {/* <Form.Item
      label="所属单位"
      name="danwei"
     
    >
    <Input />
    </Form.Item>

    <Form.Item
      label="行驶层级"
      name="mulu"
    
    >
    <Input />
    </Form.Item>
    <Form.Item
      label="办件类型"
      name="mulu"
    >
   
   <Radio.Group>
        <Radio value="a">即办件</Radio>
        <Radio value="b">承诺件</Radio>
        <Radio value="b">联办件</Radio>
        <Radio value="b">上报件</Radio>
        <Radio value="b">答复件</Radio>
        <Radio value="b">代办件</Radio>
       
      </Radio.Group>
   
    </Form.Item>
    <Form.Item
      label="是否实行告知承诺制"
      name="tell"
    //   rules={[{ required: true, message: 'Please input your username!' }]}
    >
   <Radio.Group>
        <Radio value="a">实行告知承诺制</Radio>
        <Radio value="b">不实行告知承诺制</Radio>
       
      </Radio.Group>
    </Form.Item>
    <Form.Item
      label="面向用户对象"
      name="obj"
    //   rules={[{ required: true, message: 'Please input your username!' }]}
    >
    <Checkbox.Group>
        
            <Checkbox value="A" style={{ lineHeight: '32px' }}>
              面向个人
            </Checkbox>
         
     
            <Checkbox value="B" style={{ lineHeight: '32px' }}>
              面向企业
            </Checkbox>
       
      
            <Checkbox value="C" style={{ lineHeight: '32px' }}>
              面向事业单位
            </Checkbox>
         
 
            <Checkbox value="D" style={{ lineHeight: '32px' }}>
              面向行政机关
            </Checkbox>
      
            <Checkbox value="E" style={{ lineHeight: '32px' }}>
              民办非企业单位
            </Checkbox>
       
            <Checkbox value="F" style={{ lineHeight: '32px' }}>
              社团组织
            </Checkbox>
            <Checkbox value="F" style={{ lineHeight: '32px' }}>
              面向其他组织
            </Checkbox>
          
      </Checkbox.Group>
    </Form.Item>
    <Form.Item
      label="事项主题"
      name="zhuti"
      
    >
    <Input />
    </Form.Item> */}
    <Form.Item
      label="温馨提示"
      name="toast"
      
    >
    <TextArea rows={6} />
    </Form.Item>
    <Form.Item
      label="备注"
      name="beizhu"
      
    >
     <TextArea rows={6} />
    </Form.Item>
  

   
  </Form>
        </div>
    );
}

export default Addshi;